<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称" :labelCol="labelCol">
              <j-input v-model="queryParam.projectName" placeholder="请输入项目名称" ></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目承接人" :labelCol="labelCol">
              <select-user-by-dep v-model="queryParam.undertaker" placeholder="请选择项目承接人"/>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24" :labelCol="labelCol">
            <a-form-item label="业绩归属年度" :labelCol="labelCol">
              <j-dict-select-tag type="list" v-model="queryParam.year" dictCode="yjgsnd" placeholder="请选择业绩归属年度"/>
            </a-form-item>
          </a-col>




          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="经营团队" :labelCol="labelCol">
              <select-team-input v-model="queryParam.businessTeam" :tdlx="1" placeholder="请选择经营团队" :teamType="0"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业主单位" :labelCol="labelCol">
              <select-customer-input v-model="queryParam.ownerUnit" placeholder="请选择业主单位"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="报名截止时间" :labelCol="labelCol">
              <a-range-picker
                showTime
                format="YYYY-MM-DD HH:mm:ss"
                :placeholder="['开始时间', '结束时间']"
                v-model="entriesEndDateRange"
                @change="(dates, dateStrs) => { queryParam.entriesEndDate_begin = dateStrs[0]; queryParam.entriesEndDate_end = dateStrs[1] }"
                style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="投标截止时间" :labelCol="labelCol">
              <a-range-picker
                showTime
                format="YYYY-MM-DD HH:mm:ss"
                :placeholder="['开始时间', '结束时间']"
                v-model="tenderEndDateRange"
                @change="(dates, dateStrs) => { queryParam.tenderEndDate_begin = dateStrs[0]; queryParam.tenderEndDate_end = dateStrs[1] }"
                style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="招标方式" :labelCol="labelCol">
              <j-dict-select-tag type="list" v-model="queryParam.biddingMethod" dictCode="bidding_method" placeholder="请选择招标方式"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-form-item label="招标控制价（元）" >
              <a-input-number
                :precision="2"
                v-model="queryParam.beginControlPrice"
                placeholder="请输入最小金额"
                style="width: 47%"
                @change="(val) => this.controlPriceMin = parseFloat(val)"
                :min="0"
                :max="999999999"></a-input-number>
              -
              <a-input-number
                :precision="2"
                v-model="queryParam.endControlPrice"
                placeholder="请输入最大金额"
                style="width: 47%"
                :min="controlPriceMin"
                :max="999999999"></a-input-number>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="经办人" :labelCol="labelCol">
              <select-user-by-dep
                v-model="queryParam.proposer"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="经办部门" :labelCol="labelCol">
              <j-select-depart placeholder="请选择经办部门" v-model="queryParam.proposerDeptId"/>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col style="float: left;overflow: hidden;" :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="handleReset" icon="reload" style="margin-left: 8px;">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="null"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="projectName" slot-scope="text, record" @click="onDetail(record.prepareProjectId)">{{ text }}</a>
        <span slot="notify" slot-scope="text, record">
          <a-icon
            title="催办提醒"
            v-if="record.taskUrge"
            theme="twoTone"
            twoToneColor="#eb2f96"
            @click="taskNotifyMe(flowCode,record.id)"
            type="notification"/>
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
      </a-table>
    </div>
    <!-- 项目详情开始 -->
    <erp-project-report-modal  ref="reportForm"></erp-project-report-modal>
    <erp-omc-tender-file-modal ref="modalForm" @ok="modalFormOk"></erp-omc-tender-file-modal>
    <bpm-biz-task-deal-modal
      ref="taskDealModal"
      :path="path"
      :formData="formData"
      @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
import ErpOmcTenderFileModal from './modules/ErpOmcTenderFileModal'
import { getAction, httpAction } from '@/api/manage'
import Area from '@/components/_util/Area'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'
export default {
  name: 'ErpOmcTenderFile',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpProjectReportModal,
    ErpOmcTenderFileModal,
    BpmBizTaskDealModal,
    BpmProcessTrackModal,
    BizTaskNotifyModal,
    BizTaskNotifyMeModal,
    SelectUserByDep,
    SelectCustomerInput,
    SelectTeamInput
  },
  data() {
    return {
      description: '投标档案管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '档案编号',
          align: 'center',
          dataIndex: 'finalNo',
          width: 187,
          ellipsis: true
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
          scopedSlots: { customRender: 'projectName' },
          width: 187,
          ellipsis: true
        },
        {
          title: '项目承接人',
          align: 'center',
          dataIndex: 'undertaker_dictText',
          width: 187,
          ellipsis: true
        },
        {
          title: '业绩归属年度',
          align: 'center',
          dataIndex: 'year_dictText',
          width: 187,
          ellipsis: true
        },
        {
          title: '经营团队',
          align: 'center',
          dataIndex: 'businessTeam_dictText',
          width: 187,
          ellipsis: true
        },
        {
          title: '业主单位',
          align: 'center',
          dataIndex: 'ownerUnit_dictText',
          width: 187,
          ellipsis: true
        },
        {
          title: '报名截止时间',
          align: 'center',
          dataIndex: 'entriesEndDate',
          width: 187,
          ellipsis: true
        },
        {
          title: '投标截止时间',
          align: 'center',
          dataIndex: 'tenderEndDate',
          width: 187,
          ellipsis: true
        },
        {
          title: '招标方式',
          align: 'center',
          dataIndex: 'biddingMethod_dictText',
          width: 187,
          ellipsis: true
        },
        {
          title: '招标控制价（元）',
          align: 'center',
          dataIndex: 'controlPrice',
          width: 187,
          ellipsis: true
        },
        {
          title: '变更状态',
          align: 'center',
          dataIndex: 'changeStatus_dictText',
          width: 187,
          scopedSlots: { customRender: 'bpmStatus' }
        }
      ],
      url: {
        list: '/api/erp/omc/tender/erpOmcTenderFinal/list',
        queryProjectReportById: '/api/erp/project/report/erpProjectReport/queryById',
        // delete: '/api/erp/omc/tender/erpOmcTender/delete',

        // deleteBatch: '/api/erp/omc/tender/erpOmcTender/deleteBatch',
        // exportXlsUrl: '/api/erp/omc/tender/erpOmcTender/exportXls',
        // importExcelUrl: 'api/erp/omc/tender/erpOmcTender/importExcel',
        // bizCount: '/api/erp/omc/tender/erpOmcTender/bizCount',
        queryTenderCode: '/api/erp/omc/tender/erpOmcTender/queryTenderCode'
      },
      // 代码生成后需手动设置流程编码
      flowCode: 'dev_erp_omc_tender_001',
      formUrl: 'erp/omc/tender/modules/ErpOmcTenderForm',
      formUrlMobile: '',
      dictOptions: {},
      pcaData: '',
      superFieldList: [],
      controlPriceMin: 0,
      entriesEndDateRange: [],
      tenderEndDateRange: []
    }
  },
  created() {
    this.pcaData = new Area()
    this.getSuperFieldList();
  },
  computed: {
    /* importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    } */
  },
  methods: {
    onDetail(id) {
      const that = this
      this.$nextTick(() => {
        getAction(this.url.queryProjectReportById, { id }).then((res) => {
          if (res.success) {
            const model = res.result
            that.$refs.reportForm.getDetail(model);
            that.$refs.reportForm.title = '项目一览表';
          }
        })
      })
    },
    handleAddDiy(val) {
      let httpurl = '';
      let method = '';
      httpurl += this.url.queryTenderCode;
      method = 'POST';
      httpAction(httpurl, this.model, method).then((res) => {
        this.$nextTick(() => {
          this.$refs.modalForm.title = '新增';
          res.result.applyType = val
          if (val === '2') {
            this.$refs.modalForm.title = '变更'
          }
          this.$refs.modalForm.add(res.result);
          this.$refs.modalForm.disableSubmit = false;
        })
      })
    },
    handleAddChangeDiv: function () {
      let httpurl = '';
      let method = '';
      httpurl += this.url.queryTenderCode;
      method = 'POST';
      httpAction(httpurl, this.model, method).then((res) => {
        this.$nextTick(() => {
          this.$refs.modalForm.addChange(res.result)
          this.$refs.modalForm.title = '变更'
          this.$refs.modalForm.disableSubmit = false
        })
      })
    },
    getPcaText(code) {
      return this.pcaData.getText(code);
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' })
      fieldList.push({ type: 'string', value: 'proposer', text: '经办人', dictCode: '' })
      fieldList.push({ type: 'sel_depart', value: 'proposerDeptId', text: '经办部门' })
      fieldList.push({ type: 'string', value: 'tenderCode', text: '投标编号', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'prepareProjectId',
        text: '选择预立项项目',
        dictCode: 'erp_omc_prepare_project,mc,id'
      })
      fieldList.push({ type: 'string', value: 'projectName', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'projectType', text: '项目类型', dictCode: 'xmlx_type' })
      fieldList.push({ type: 'string', value: 'undertaker', text: '承接人', dictCode: '' })
      fieldList.push({ type: 'int', value: 'year', text: '业绩归属年度', dictCode: 'yjgsnd' })
      fieldList.push({ type: 'pca', value: 'projectAddress', text: '项目地址' })
      fieldList.push({ type: 'string', value: 'businessTeam', text: '经营团队', dictCode: 'teams' })
      fieldList.push({ type: 'date', value: 'entriesEndDate', text: '报名截止日期' })
      fieldList.push({ type: 'date', value: 'tenderEndDate', text: '投标截止日期' })
      fieldList.push({ type: 'string', value: 'ownerUnit', text: '业主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'ownerLinkman', text: '业主联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'ownerTel', text: '业主联系方式', dictCode: '' })
      fieldList.push({ type: 'string', value: 'biddingMethod', text: '招标方式', dictCode: 'bidding_method' })
      fieldList.push({ type: 'string', value: 'controlPrice', text: '招标控制价（元）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'entryFee', text: '标书费（元）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderBond', text: '投标保证金（元）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderContent', text: '投标内容概要', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderFile', text: '投标文件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenderType', text: '投标类别', dictCode: 'tender_type' })
      fieldList.push({ type: 'string', value: 'baseScore', text: '基准分值', dictCode: '' })
      fieldList.push({ type: 'string', value: 'isTeamwork', text: '是否协同', dictCode: 'YES_OR_NO' })
      fieldList.push({ type: 'string', value: 'teamworkPerson', text: '协同部门到人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bpmStatus', text: '流程状态', dictCode: 'bpm_status' })
      this.superFieldList = fieldList
    },
    handleReset() {
      this.entriesEndDateRange = [];
      this.tenderEndDateRange = [];
      this.allSearchReset();
    }
  }
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
</style>
